<template>
  <div>
    <el-dialog title="预警管理" :visible.sync="isManagement" width="60%" :before-close="handleClose" :close-on-click-modal='false'>
      <el-form ref="form" :model="form" label-width="100px" label-position="left" size="small">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="学生姓名：">
              {{this.form.real_name}}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="性别：">
              {{this.form.sex}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="学段：">
              {{this.form.section_title}}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="年级：">
              {{this.form.grade_title}}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="班级：">
              {{this.form.class_title}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="预警方式：">
          {{this.form.mode}}
        </el-form-item>
        <el-form-item label="问题类型：">
          {{this.form.question_type}}
        </el-form-item>
        <el-form-item label="问题程度：">
          {{this.form.problem_degree}}
        </el-form-item>
        <el-form-item label="预警管理：">
          <el-select v-model="form.status" placeholder="请选择">
            <el-option v-for="item in options.status_list" :key="item.id" :label="item.title" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注说明：">
          <el-input type="textarea" placeholder="请输入内容" v-model="form.management_notes" maxlength="1000" show-word-limit> </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close()">取 消</el-button>
        <el-button type="primary" @click="checkFn()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {APIEARLYWARNINGGETSUNDRY, APIEARLYWARNINGGETINFO, APIEARLYWARNINGMANAGEMENT} from '@/common/api.js'
export default {
  props: ['isManagement', 'id'],
  data () {
    return {
      form: {
        status: '',
        management_notes: ''
      },
      options: {}
    }
  },
  created () {
    this.selectFn()
    this.setDataFn()
  },
  methods: {
    handleClose () {
      this.$emit('noManagement')
    },
    close (type) {
      this.$emit('noManagement', type)
    },
    setDataFn () {
      APIEARLYWARNINGGETINFO({
        early_warning_id: this.id
      }).then((res) => {
        this.form = res.data
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    },
    selectFn () {
      APIEARLYWARNINGGETSUNDRY().then((res) => {
        this.options = res.data
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    },
    checkFn () {
      APIEARLYWARNINGMANAGEMENT({
        early_warning_id: this.id,
        status: this.form.status,
        management_notes: this.form.management_notes
      }).then((res) => {
        this.$message.success(res.msg)
        this.close(1)
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>
